// 
// Decompiled by Procyon v0.5.36
// 

package com.akamai.botman;

import android.os.*;
import android.util.*;
import java.util.*;
import java.util.concurrent.*;

public final class k implements java.util.Observer
{
    com.akamai.botman.j a;
    boolean b;
    long c;
    public java.util.ArrayList<com.akamai.botman.l> d;
    private java.util.concurrent.Future<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>> e;
    
    k() {
        this.a = null;
        this.b = false;
        this.c = 0L;
        this.d = new java.util.ArrayList<com.akamai.botman.l>();
        this.e = null;
    }
    
    public final void a() throws java.lang.Exception {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        if (!this.a.a()) {
            com.akamai.botman.al.c("MotionManager", "Motion listener registration failed", new java.lang.Throwable[0]);
            return;
        }
        this.b = true;
        this.a.addObserver(this);
    }
    
    public final void b() throws java.lang.Exception {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.a.b();
        this.a.deleteObservers();
    }
    
    public final void c() {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.c = android.os.SystemClock.uptimeMillis();
        this.d.clear();
        this.f();
    }
    
    public final com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long> d() {
        if (this.e != null) {
            try {
                return this.e.get();
            }
            catch (java.lang.InterruptedException ex) {
                com.akamai.botman.al.b("MotionManager", "Failed to get motion data: " + ex.getMessage(), new java.lang.Throwable[0]);
            }
            catch (java.util.concurrent.ExecutionException ex2) {
                com.akamai.botman.al.b("MotionManager", "Failed to get motion data: " + ex2.getMessage(), new java.lang.Throwable[0]);
            }
        }
        return this.e();
    }
    
    private com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long> e() {
        if (this.d.size() > 1) {
            try {
                final java.lang.Throwable[] array = new java.lang.Throwable[0];
                final long uptimeMillis = android.os.SystemClock.uptimeMillis();
                final int n;
                final float[] array2 = new float[n = (int)com.akamai.botman.ak.a(this.d.size())];
                final float[] array3 = new float[n];
                final float[] array4 = new float[n];
                final float[] array5 = new float[n];
                final float[] array6 = new float[n];
                final float[] array7 = new float[n];
                final float[] array8 = new float[n];
                final float[] array9 = new float[n];
                final float[] array10 = new float[n];
                final float[] array11 = new float[n];
                long n2 = this.c;
                int n3 = 0;
                for (final com.akamai.botman.l l : this.d) {
                    array2[n3] = l.d;
                    array3[n3] = l.e;
                    array4[n3] = l.f;
                    array5[n3] = l.a;
                    array6[n3] = l.b;
                    array7[n3] = l.c;
                    array8[n3] = l.g;
                    array9[n3] = l.h;
                    array10[n3] = l.i;
                    array11[n3] = (float)java.lang.Math.max(0L, l.j - n2);
                    new java.lang.StringBuilder("Motion string: ").append(array2[n3]).append(",").append(array3[n3]).append(",").append(array4[n3]).append(",").append(array5[n3]).append(",").append(array6[n3]).append(",").append(array7[n3]).append(",").append(array8[n3]).append(",").append(array9[n3]).append(",").append(array10[n3]).append(" / time(ms): ").append(android.os.SystemClock.uptimeMillis() - l.j);
                    final java.lang.Throwable[] array12 = new java.lang.Throwable[0];
                    n2 = l.j;
                    if (++n3 >= n) {
                        break;
                    }
                }
                final android.util.Pair<java.lang.String, java.lang.Long> a = com.akamai.botman.ah.a(array2, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a2 = com.akamai.botman.ah.a(array3, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a3 = com.akamai.botman.ah.a(array4, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a4 = com.akamai.botman.ah.a(array5, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a5 = com.akamai.botman.ah.a(array6, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a6 = com.akamai.botman.ah.a(array7, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a7 = com.akamai.botman.ah.a(array8, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a8 = com.akamai.botman.ah.a(array9, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a9 = com.akamai.botman.ah.a(array10, 0.6f);
                final android.util.Pair<java.lang.String, java.lang.Long> a10 = com.akamai.botman.ah.a(array11, 0.0f);
                final java.lang.String string = (java.lang.String)a.first + ":" + (java.lang.String)a2.first + ":" + (java.lang.String)a3.first + ":" + (java.lang.String)a4.first + ":" + (java.lang.String)a5.first + ":" + (java.lang.String)a6.first + ":" + (java.lang.String)a7.first + ":" + (java.lang.String)a8.first + ":" + (java.lang.String)a9.first;
                final long n4 = (long)a.second + (long)a2.second + (long)a3.second + (long)a4.second + (long)a5.second + (long)a6.second + (long)a7.second + (long)a8.second + (long)a9.second;
                final com.akamai.botman.i i = new com.akamai.botman.i();
                java.lang.String string2 = "";
                long n5 = this.c;
                int n6 = 0;
                for (final com.akamai.botman.l j : this.d) {
                    final com.akamai.botman.i k = i;
                    final com.akamai.botman.l m = j;
                    final long n7 = n5;
                    final com.akamai.botman.l l2 = m;
                    final com.akamai.botman.i i2 = k;
                    final java.lang.String format = k.a.format(l2.d);
                    final java.lang.String format2 = i2.a.format(l2.e);
                    final java.lang.String format3 = i2.a.format(l2.f);
                    final java.lang.String format4 = i2.a.format(l2.a);
                    final java.lang.String format5 = i2.a.format(l2.b);
                    final java.lang.String format6 = i2.a.format(l2.c);
                    final java.lang.String format7 = i2.a.format(l2.g);
                    final java.lang.String format8 = i2.a.format(l2.h);
                    final java.lang.String format9 = i2.a.format(l2.i);
                    long n8;
                    if ((n8 = l2.j - n7) < 0L) {
                        n8 = 0L;
                    }
                    final long n9 = n8 + java.lang.Math.round((java.lang.Float.parseFloat(format) + java.lang.Float.parseFloat(format2) + java.lang.Float.parseFloat(format3) + java.lang.Float.parseFloat(format4) + java.lang.Float.parseFloat(format5) + java.lang.Float.parseFloat(format6) + java.lang.Float.parseFloat(format7) + java.lang.Float.parseFloat(format8) + java.lang.Float.parseFloat(format9)) * 100.0f);
                    final java.lang.String string3 = n8 + "," + format + "," + format2 + "," + format3 + "," + format4 + "," + format5 + "," + format6 + "," + format7 + "," + format8 + "," + format9 + "," + l2.k + ";";
                    new java.lang.StringBuilder("Motion string : ").append(string3).append(" time(ms): ").append(android.os.SystemClock.uptimeMillis() - l2.j);
                    final java.lang.Throwable[] array13 = new java.lang.Throwable[0];
                    string2 += (java.lang.String)new android.util.Pair((java.lang.Object)string3, (java.lang.Object)n9).first;
                    n5 = j.j;
                    if (++n6 >= 10) {
                        break;
                    }
                }
                final com.akamai.botman.am am = new com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>(string2, string, a10.first);
                final long n10 = android.os.SystemClock.uptimeMillis() - uptimeMillis;
                com.akamai.botman.al.a("MotionManager", "Motion Count SDCalc-Time: " + n + "/" + this.d.size(), new java.lang.Throwable[0]);
                com.akamai.botman.al.a("MotionManager", "Motion SDCalc-Time: " + n10 + "ms", new java.lang.Throwable[0]);
                return new com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>(am, n4, (long)n);
            }
            catch (java.lang.Exception ex) {
                com.akamai.botman.al.b("MotionManager", "Exception in getting motion events", ex);
                com.akamai.botman.f.a(ex);
            }
        }
        return new com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>(new com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>("", "", ""), 0L, 0L);
    }
    
    @java.lang.Override
    public final void update(final java.util.Observable observable, java.lang.Object data) {
        try {
            final java.lang.Throwable[] array = new java.lang.Throwable[0];
            if (data == null) {
                return;
            }
            if (this.d.size() >= 128) {
                this.b();
                this.f();
                data = java.util.concurrent.Executors.newFixedThreadPool(1);
                this.e = ((java.util.concurrent.ExecutorService)data).<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>>submit((java.util.concurrent.Callable<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>>)new com.akamai.botman.k.a());
                return;
            }
            this.d.add((com.akamai.botman.l)data);
        }
        catch (java.lang.Exception ex) {
            com.akamai.botman.al.b("MotionManager", "Exception in processing motion event", ex);
            com.akamai.botman.f.a(ex);
        }
    }
    
    private void f() {
        if (this.e != null) {
            if (!this.e.isCancelled() && !this.e.isDone()) {
                this.e.cancel(true);
            }
            this.e = null;
        }
    }
    
    final class a implements java.util.concurrent.Callable<com.akamai.botman.am<com.akamai.botman.am<java.lang.String, java.lang.String, java.lang.String>, java.lang.Long, java.lang.Long>>
    {
    }
}
